home *** CD-ROM | disk | FTP | other *** search
/ Palm Utilities / Palm_Utilities_CD-ROM_2001_2001.iso / files / pim / Hot Date 1.3e / hotdate.exe / hotdate / timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-24  |  4.1 KB  |  156 lines

  1. /* $Id: timer.c,v 1.8 1999/07/24 04:55:33 chrisf Exp $ */
  2.  
  3. /*
  4. Hot Date - A DatebookDB displayer for the PalmPilot
  5. Copyright (C) 1999 Chris Faherty
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20. */
  21.  
  22. #include <Pilot.h>
  23. #include "callback.h"
  24. #include "hotdate.h"
  25. #include "hotdateRsc.h"
  26. #include "timer.h"
  27.  
  28. /*
  29.  * Static function prototypes
  30.  */
  31. static Boolean ShowAlarmHandleEvent(EventPtr event);
  32.  
  33. void SetTimeOfNextAlarm(ULong alarmTime, DWord ref)
  34. {
  35.     UInt cardNo;
  36.     LocalID dbID;
  37.     DmSearchStateType searchInfo;
  38.  
  39.     if (DmGetNextDatabaseByTypeCreator(true, &searchInfo, 
  40.         sysFileTApplication, MainAppID, true, &cardNo, &dbID)) return;
  41.  
  42.     AlmSetAlarm(cardNo, dbID, ref, alarmTime, 0);
  43. }
  44.  
  45. ULong GetTimeOfNextAlarm(DWordPtr ref)
  46. {
  47.     UInt cardNo;
  48.     LocalID dbID;
  49.     DmSearchStateType searchInfo;
  50.  
  51.     if (DmGetNextDatabaseByTypeCreator(true, &searchInfo, 
  52.         sysFileTApplication, MainAppID, true, &cardNo, &dbID)) return 0;
  53.  
  54.     return AlmGetAlarm(cardNo, dbID, ref);
  55. }
  56.  
  57. static Boolean ShowAlarmHandleEvent(EventPtr event)
  58. {
  59.     FormPtr frm;
  60.     Boolean result=false;
  61.  
  62.     CALLBACK_PROLOGUE
  63.  
  64.     /*
  65.      * We don't want to allow an other application to be launched 
  66.      * while an alarm is displayed, so we intercept appStop events.
  67.      * All other event are handled by FrmDoDialog.
  68.      */
  69.     if (event->eType == appStopEvent) result = true;
  70.  
  71.     /*
  72.      * I don't like the launch silk-screen button being pressed
  73.      * during the alarm dialog.  It doesn't do anything and is
  74.      * quite confusing to the user.
  75.      */
  76.     else if ((event->eType == keyDownEvent) &&
  77.             (event->data.keyDown.modifiers & commandKeyMask) &&
  78.             (event->data.keyDown.chr == launchChr)) result = true;
  79.  
  80.     else if (event->eType == frmUpdateEvent) {
  81.         frm = FrmGetActiveForm();
  82.         FrmDrawForm(frm);
  83.     }
  84.  
  85.     CALLBACK_EPILOGUE
  86.  
  87.     return result;
  88. }
  89.  
  90. void DisplayAlarm(void)
  91. {
  92.     FormPtr frm;
  93.     FormPtr curForm;
  94.     DWord ref;
  95.  
  96.     frm = FrmInitForm(AlarmForm);
  97.     
  98.     curForm = FrmGetActiveForm();
  99.     if (curForm) FrmSetActiveForm(frm);
  100.     
  101.     /* Set the event handler for the alarm dialog. */
  102.     FrmSetEventHandler(frm, ShowAlarmHandleEvent);
  103.     FrmDrawForm(frm);
  104.         
  105.     /* Display the alarm dialog. */
  106.     FrmDoDialog(frm);
  107.  
  108.      FrmDeleteForm(frm);
  109.     
  110.     FrmSetActiveForm(curForm);
  111.  
  112.     /*
  113.      * Cancel any scheduled repeating alarm sounds.
  114.      */
  115.     if (GetTimeOfNextAlarm(&ref) && (ref > 0)) SetTimeOfNextAlarm(0, 0);
  116. }
  117.  
  118. void AlarmTriggered(SysAlarmTriggeredParamType * cmdPBP)
  119. {
  120.     ULong alarmTime;
  121.     DWord ref;
  122.  
  123.     alarmTime = 0;
  124.     ref = 0;
  125.     
  126.     /*
  127.      * The reference value contains the number of times the alarm has
  128.      * sounded for an event.
  129.      */
  130.     if (cmdPBP->ref == 0) {
  131.         /*
  132.          * This is the first alarm.  Since we don't disable the display
  133.          * we should expect a sysAppLaunchCmdDisplayAlarm shortly.
  134.          */
  135.         /* Play the alarm sound. */
  136.         SndPlaySystemSound(sndAlarm);
  137.     } else {
  138.         /*
  139.          * Pass the following value to the alarm manager, this will be 
  140.          * removed from the alarm table and the display notification will
  141.          * NOT be generated for it.  We don't want display notifications
  142.          * on repeat sounds.
  143.          */
  144.         cmdPBP->purgeAlarm = true;
  145.         /* Play the alarm sound. */
  146.         SndPlaySystemSound(sndAlarm);
  147.     }
  148.     
  149.     if (cmdPBP->ref < 2) {
  150.         alarmTime = TimGetSeconds()+30;
  151.         ref = cmdPBP->ref+1;
  152.     }
  153.  
  154.     if (alarmTime) SetTimeOfNextAlarm(alarmTime, ref);                
  155. }
  156.